/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.sys.web.user;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.thinkgem.jeesite.modules.hk.adv.entity.HkAdvComment;
import com.thinkgem.jeesite.modules.hk.adv.service.HkAdvCommentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;


/**
 * 用户评论Controller
 * @author 罗天文
 * @version 2018-03-14
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/user/hkAdvComment")
public class HkUserAdvCommentController extends BaseController {

	@Autowired
	private HkAdvCommentService hkAdvCommentService;
	
	@ModelAttribute
	public HkAdvComment get(@RequestParam(required=false) String id) {
		HkAdvComment entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkAdvCommentService.get(id);
		}
		if (entity == null){
			entity = new HkAdvComment();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:user:hkAdvComment:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkAdvComment hkAdvComment, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkAdvComment> page = hkAdvCommentService.findPage(new Page<HkAdvComment>(request, response), hkAdvComment); 
		model.addAttribute("page", page);
		return "hk/sys/user/hkAdvCommentList";
	}

	@RequiresPermissions("sys:user:hkAdvComment:view")
	@RequestMapping(value = "form")
	public String form(HkAdvComment hkAdvComment, Model model) {
		model.addAttribute("hkAdvComment", hkAdvComment);
		return "hk/sys/user/hkAdvCommentForm";
	}

	@RequiresPermissions("sys:user:hkAdvComment:edit")
	@RequestMapping(value = "save")
	public String save(HkAdvComment hkAdvComment, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkAdvComment)){
			return form(hkAdvComment, model);
		}
		hkAdvCommentService.save(hkAdvComment);
		addMessage(redirectAttributes, "保存用户评论成功");
		return "redirect:"+Global.getAdminPath()+"/sys/user/hkAdvComment/?repage";
	}
	
	@RequiresPermissions("sys:user:hkAdvComment:edit")
	@RequestMapping(value = "delete")
	public String delete(HkAdvComment hkAdvComment, RedirectAttributes redirectAttributes) {
		hkAdvCommentService.delete(hkAdvComment);
		addMessage(redirectAttributes, "删除用户评论成功");
		return "redirect:"+Global.getAdminPath()+"/sys/user/hkAdvComment/?repage";
	}

}